package tests.pl.shenlon.ga;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import pl.shenlon.ga.Genom;
import pl.shenlon.ga.SimpleChromosome;
import pl.shenlon.poker.game.GameState;

public class SimpleGenomTest {

	private SimpleChromosome genom;

	@Before
	public void setUp() {
		genom = new SimpleChromosome();
	}

	@Test
	public void testConstructors() {
		Assert.assertNotNull(genom);
		Assert.assertNotSame(genom, new SimpleChromosome(genom));
		Assert.assertNotSame(genom,
				new SimpleChromosome(genom.getBehaviourPattern(GameState.ANY)));
		Assert.assertNotSame(genom,
				new SimpleChromosome(genom.getBehaviourPattern(GameState.ANY)
						.getPattern()));

		Assert.assertEquals(genom, new SimpleChromosome(genom));
		Assert.assertEquals(genom,
				new SimpleChromosome(genom.getBehaviourPattern(GameState.ANY)));
		Assert.assertEquals(genom,
				new SimpleChromosome(genom.getBehaviourPattern(GameState.ANY)
						.getPattern()));

		SimpleChromosome genomCopy = new SimpleChromosome(genom);
		Assert.assertEquals(genom, genomCopy);
		genomCopy.getBehaviourPattern(GameState.ANY).setBluffChance(1000);
		Assert.assertFalse(genom.equals(genomCopy));

		Assert.assertNotSame(genom.getBehaviourPattern(GameState.ANY),
				genomCopy.getBehaviourPattern(GameState.ANY));
		Assert.assertNotSame(genom.getBehaviourPattern(GameState.ANY)
				.getPattern(), genomCopy.getBehaviourPattern(GameState.ANY)
				.getPattern());
	}

	@Test
	public void testCreateRandomizedGenom() {
		Genom genom = SimpleChromosome.createRandomizedGenom();
		Assert.assertNotNull(genom);
		Genom emptyGenom = new SimpleChromosome(new int[]{0, 0, 0, 0, 0});
		Assert.assertFalse(genom.equals(emptyGenom));
	}

	@Test
	public void testMutate() {
		Assert.assertFalse(genom.mutate(0.0));
		Assert.assertTrue(genom.mutate(1.0));

		SimpleChromosome genom = new SimpleChromosome(new int[]{100, 100, 100, 100, 100});
		Genom genomCopy = new SimpleChromosome(genom);
		genomCopy.mutate(1.0);
		Assert.assertFalse(genom.equals(genomCopy));
	}
}
